package com.z6pin.user.z6pinuser.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.z6pin.user.z6pinuser.domain.Person;

@Service
public class PersonHystrixService {

	@Autowired
	PersonService personService; 
	//com.z6pin.user.z6pinuser.service.PersonService;
	@HystrixCommand(fallbackMethod = "fallbackSave") //1
	public List<Person> save(String name) {
		return personService.save(name);
		//return new ArrayList<Person>();
	}
	
	public List<Person> fallbackSave(String name){ 
		List<Person> list = new ArrayList<>();
		Person p = new Person(name+"没有保存成功，Person Service 故障");
		list.add(p);
		return list;
	}
	
	@HystrixCommand(fallbackMethod = "fallbackgetDjg") //1
	public Person getDjg(Person person) {
		return personService.getDjg(person);
		//return new Person();
	}
	
	public List<Person> fallbackgetDjg(Person person){ 
		List<Person> list = new ArrayList<>();
		Person p = new Person(person.getName()+"没有保存成功，Person Service 故障");
		list.add(p);
		return list;
	}
}
